﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace GameTools
{
	class Log
	{
	    static FileStream smFile = null;
	    static string strPath = "";
	    static string filename = "";

	    static StreamWriter sw = null;

	    public static void WriteLog(string sMsg)
	    {
	        if (sMsg != "")
	        {
	            try
	            {
	                if (smFile == null)
	                {
	                    strPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log\\";
	                    filename = DateTime.Now.ToString("yy-MM-dd HH-mm-ss") + ".log";

	                    if (!System.IO.Directory.Exists(strPath))
	                    {
	                        Directory.CreateDirectory(strPath);
	                    }

	                    smFile = new FileStream(strPath + filename, FileMode.Create);
	                    sw = new StreamWriter(smFile);

	                    //smFile.Close();
	                }

	                if (smFile != null)
	                {
	                   
	                    sw.WriteLine(DateTime.Now.ToString() + " $$ " + sMsg + "\n");
	                    sw.Flush();
	                    //sw.Close();

	//                    FileInfo fi = smFile. new FileInfo(strPath + filename);
	//                    if (!fi.Exists)
	//                    {
	//                        using (StreamWriter sw = fi.CreateText())
	//                        {
	//                            sw.WriteLine(DateTime.Now.ToString() + " $$ " + "\n" + sMsg + "\n");
	//                            sw.Close();
	//                        }
	//                    }
	//                    else
	//                    {
	//                        using (StreamWriter sw = fi.AppendText())
	//                        {
	//                            sw.WriteLine(DateTime.Now.ToString() + " $$ " + "\n" + sMsg + "\n");
	//                            sw.Close();
	//                        }
	//                    }
	                }
	            }
	            catch(Exception ex)
	            {
	                Console.WriteLine(ex.Message);
	            }
	        }
	    }
	}
}